<template>
    <div class="h-header">
        <span class="logo">
            <el-icon class="mr-1"><eleme-filled /></el-icon>
            <span class="font-bold ml-2">韩城味道</span>
        </span>
        <el-icon class="icon-btn" @click="$store.commit('handleAsideWidth')">
            <fold v-if="$store.state.asideWidth == '250px'" />
            <Expand v-else />
        </el-icon>
        <el-tooltip effect="dark" content="刷新" placement="bottom">
            <el-icon class="icon-btn" @click="handleRefresh">
                <refresh />
            </el-icon>
        </el-tooltip>

        <div class="ml-auto flex items-center">
            <el-tooltip effect="dark" content="全屏" placement="bottom">
                <el-icon class="icon-btn" @click="toggle"><full-screen /></el-icon>
            </el-tooltip>

            <el-dropdown class="dropdown" @command="handleCommand">
                <span class="flex item-center justify-center text-light-50">
                    <el-avatar class="mr-2" :size="45" :src="$store.state.user.avatar" />
                    <div class="flex justify-center items-center">
                        {{ $store.state.user.username }}
                        <el-icon class="el-icon--right">
                            <arrow-down />
                        </el-icon>
                    </div>

                </span>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item command="repassword">修改密码</el-dropdown-item>
                        <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </div>
    <form-drawer ref="formDrawerRef" size="30%" title="修改密码" destroyOnClose @submit="onSubmit">
        <el-form ref="formRef" :model="form" :rules="rules" class="w-[250px]" label-width="80px" size="small">
            <el-form-item prop="oldpassword" label="旧密码">
                <el-input v-model="form.oldpassword" placeholder="请输入旧密码">

                </el-input>
            </el-form-item>
            <el-form-item prop="password" type="password" label="新密码">
                <el-input v-model="form.password" placeholder="请输入新密码" show-password>

                </el-input>
            </el-form-item>
            <el-form-item prop="repassword" type="password" label="确认密码">
                <el-input v-model="form.repassword" placeholder="请确认新密码" show-password>

                </el-input>
            </el-form-item>
        </el-form>
    </form-drawer>
</template>
<script setup>
import FormDrawer from "~/components/FormDrawer.vue";
import { useFullscreen } from '@vueuse/core'
import { useRepassword,useLogout } from "~/composables/useManager";
const {
    formDrawerRef,
    form,
    rules,
    formRef,
    onSubmit,
    openRePasswordForm
} = useRepassword()
const {
    handleLogout
} = useLogout()

const { toggle } = useFullscreen()

const handleCommand = (c) => {
    switch (c) {
        case "logout":
            handleLogout()
            break;
        case "repassword":
            openRePasswordForm()
            break;
    }
}

const handleRefresh = () => location.reload()



</script>
<style>
.h-header {
    @apply flex items-center bg-indigo-500 text-light-700 fixed top-0 left-0 right-0;
    height: 64px;
    z-index: 1000;
}

.logo {
    width: 150px;
    @apply flex justify-center items-center text-xl font-thin;
}

.icon-btn {
    @apply flex justify-center items-center;
    width: 42px;
    height: 64px;
    cursor: pointer;
}

.icon-btn:hover {
    @apply bg-indigo-600;
}

.dropdown {
    height: 64px;
    cursor: pointer;
    @apply flex justify-center items-center mx-5
}
</style>